package com.lv.service.adapter

import android.widget.EditText
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.SizeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.lv.common.base.DataBindBaseViewHolder
import com.lv.common.bean.FactoryBorderBeans
import com.lv.common.bean.FactoryBorderItemBean
import com.lv.common.imp.OnPositionMore
import com.lv.common.imp.OnPositionTListener
import com.lv.common.widget.recyclerview.decoration.SpacesItemDecoration
import com.lv.service.R
import com.lv.service.databinding.ItemFactoryBorderDialogBinding

/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class FactoryBorderAdapter(private val datas: MutableList<FactoryBorderBeans>) :
    BaseQuickAdapter<FactoryBorderBeans, DataBindBaseViewHolder>
        (R.layout.item_factory_border_dialog, datas) {

    override fun convert(helper: DataBindBaseViewHolder, item: FactoryBorderBeans) {
        val mBinding: ItemFactoryBorderDialogBinding =
            helper.getBind() as ItemFactoryBorderDialogBinding
        mBinding.itemRoot = item
//        //防止列表闪烁
        mBinding.executePendingBindings()
        val layoutPosition = helper.layoutPosition
        val clParent = helper.getView<ConstraintLayout>(R.id.cl_parent)
        val rvChild: RecyclerView = helper.getView<RecyclerView>(R.id.rv_child)
        val gridLayoutParams = GridLayoutManager(context, 3)
        rvChild.layoutManager = gridLayoutParams
        val imageList = item.imageList
        val list = mutableListOf<FactoryBorderItemBean>()
        imageList?.let {
            list.addAll(imageList)
        }
        val adapter = FactoryBorderChildAdapter(list)
        rvChild.adapter = adapter
//        rvChild.addItemDecoration(
//            SpacesItemDecoration(
//                SizeUtils.dp2px(10.0f),
//                SizeUtils.dp2px(14.0f),
//                false
//            )
//        )
        adapter.onViewClickListener = OnPositionTListener { position, data ->
            onViewClickListener?.onClick(layoutPosition, position, data = item)
        }

//        tvName.text = item.name
//        val layoutParams = clParent.layoutParams as RecyclerView.LayoutParams
//        if (layoutPosition == datas.size - 1) {
//            layoutParams.bottomMargin = SizeUtils.dp2px(40.0f)
//        } else {
//            layoutParams.bottomMargin = SizeUtils.dp2px(0.0f)
//        }
//        clParent.layoutParams = layoutParams


    }

    var onViewClickListener: OnPositionMore<FactoryBorderBeans>? = null


}